Add Text to a Cell

Hi, I'm trying to add or edit a specific cell in the module using DXL. Even though it appears that I have found the cell in the for/do loop, it would simply create another object when I use "object."Object Text" = aString" above the one I'm on. It also puts the text in the main text cell, rather than the one I want. Does anyone know how to do this?


JennC - Fri Jul 12 15:45:50 EDT 2013

Re: Add Text to a Cell
Mike.Scharnow - Sat Jul 13 01:23:13 EDT 2013

Hi,

Hm, I'm trying to understand what the situation is you currently face.

If you say "cell", do you mean a cell of a DOORS table? Or do you mean an attribute of an object? If not, what is the "main text cell"?

Perhaps you can post a screenshot of the module that you want to manipulate.

Additionally: "object" should not be used as a variable name, because "object" is a reserved keyword in DOORS. Better use oCurrent or something like that.

BR,

Mike

Re: Add Text to a Cell
JennC - Mon Jul 15 09:05:25 EDT 2013

Mike.Scharnow - Sat Jul 13 01:23:13 EDT 2013

Hi,

Hm, I'm trying to understand what the situation is you currently face.

If you say "cell", do you mean a cell of a DOORS table? Or do you mean an attribute of an object? If not, what is the "main text cell"?

Perhaps you can post a screenshot of the module that you want to manipulate.

Additionally: "object" should not be used as a variable name, because "object" is a reserved keyword in DOORS. Better use oCurrent or something like that.

BR,

Mike

By cell, I meant a specific row or value, that already exists, of an attribute. For example, if I had an attribute called "comments", I would want to change the value under "comments" in the first row of the module.

Additionally: "object" should not be used as a variable name, because "object" is a reserved keyword in DOORS.

Sorry, that bit was confusing, I meant the variable would be of type object.

Thanks,

Jenn

Re: Add Text to a Cell
GregM_dxler - Mon Jul 15 09:23:49 EDT 2013

JennC - Mon Jul 15 09:05:25 EDT 2013

By cell, I meant a specific row or value, that already exists, of an attribute. For example, if I had an attribute called "comments", I would want to change the value under "comments" in the first row of the module.

Additionally: "object" should not be used as a variable name, because "object" is a reserved keyword in DOORS.

Sorry, that bit was confusing, I meant the variable would be of type object.

Thanks,

Jenn

Good morning,

Sounds like there is still some confusion on naming.  I don't believe she is talking about rows, columns and cells in DOORS tables, but instead objects with attributes.

It might help to post a snippet of the dxl code.  A couple of ideas that might help.

1) After changing the attribute value (o."comments" "" = "New text") you will probably need to refresh the current Module to see the update.

2) If the attribute is a text field, add in the "" after the attribute name, so the declaration gets in the proper cast.

3) You should be declaring a variable, such as o, to represent the object (Object o) and not the attribute name.  This is probably why it is adding a new object. 

4) Your main text cell that you say, is the main column and that is normally the attribute "Object Text" (actually DOORS will display the Object Heading attribute if there is something there, otherwise it will display the Object Text attribute).

5) To change a different object attribute (your column), you need to use that attribute name instead of "Object Text".  You can find out what the name is by right clicking on the column name and looking at the properties (providing the column is just an attribute and not a dxl attribute).

A simple dxl script to set object text:

Object o

string s = "my text"

for o in current Module do {

o."Object Text" "" = s

}

refresh current Module

Hope this helps,

Greg

Re: Add Text to a Cell
JennC - Mon Jul 15 09:37:50 EDT 2013

GregM_dxler - Mon Jul 15 09:23:49 EDT 2013

Good morning,

Sounds like there is still some confusion on naming.  I don't believe she is talking about rows, columns and cells in DOORS tables, but instead objects with attributes.

It might help to post a snippet of the dxl code.  A couple of ideas that might help.

1) After changing the attribute value (o."comments" "" = "New text") you will probably need to refresh the current Module to see the update.

2) If the attribute is a text field, add in the "" after the attribute name, so the declaration gets in the proper cast.

3) You should be declaring a variable, such as o, to represent the object (Object o) and not the attribute name.  This is probably why it is adding a new object. 

4) Your main text cell that you say, is the main column and that is normally the attribute "Object Text" (actually DOORS will display the Object Heading attribute if there is something there, otherwise it will display the Object Text attribute).

5) To change a different object attribute (your column), you need to use that attribute name instead of "Object Text".  You can find out what the name is by right clicking on the column name and looking at the properties (providing the column is just an attribute and not a dxl attribute).

A simple dxl script to set object text:

Object o

string s = "my text"

for o in current Module do {

o."Object Text" "" = s

}

refresh current Module

Hope this helps,

Greg

This is my code snippet. It is trying to locate the 4th attribute of the first row to change.

s = "my test"

Object anObject
Column col
for anObject in current Module do {
    int colCount = 0
    for col in current Module do {
     colCount++

// Get the object for column 4 of the first row and change that.
  if ( colCount == 4 && number(anObject) == "1" )
  {
      anObject."Object Text" = s
   break
  }
 }
    break
}

 

This adds a new object or row to the module. I tried putting your code in, Greg:

o."Object Text" "" = s

but it didn't actually add anything to the module.

Re: Add Text to a Cell
GregM_dxler - Mon Jul 15 10:12:23 EDT 2013

JennC - Mon Jul 15 09:37:50 EDT 2013

This is my code snippet. It is trying to locate the 4th attribute of the first row to change.

s = "my test"

Object anObject
Column col
for anObject in current Module do {
    int colCount = 0
    for col in current Module do {
     colCount++

// Get the object for column 4 of the first row and change that.
  if ( colCount == 4 && number(anObject) == "1" )
  {
      anObject."Object Text" = s
   break
  }
 }
    break
}

 

This adds a new object or row to the module. I tried putting your code in, Greg:

o."Object Text" "" = s

but it didn't actually add anything to the module.

Hi Jenn,

Let's assume that the columns you are looking at are just attributes.

You can find out what attribute this is by the command attrName(col), which will give you a string.  Then you can use that attribute name to set the value.

number(anObject) gives you the object number, not the absolute number (or object identifier).  Is this what you really want?

The second break will break out of for anObject in current Module loop after the first object.  If so, then why even use a loop?

Adding the code doesn't work since I used "o" as the object variable and not "anObject" as you used.

I modified your code to go through the entire module and it will change the text in the 4th column of the object number 1 (providing you have it in edit mode).  Hope this helps you a little.

s = "my test"

Object anObject
Column col
for anObject in current Module do {
    int colCount = 0
    for col in current Module do {
        colCount++
        print "OID=" number(anObject) "  Column=" colCount "\n"
        // Get the object for column 4 of the first row and change that.
        if ( colCount == 4 && number(anObject) == "1" ) {
            string sAttr = attrName(col)
            anObject.sAttr = s
            break
        }
    }
    //break
}
print "done"

Greg

Re: Add Text to a Cell
JennC - Mon Jul 15 10:28:00 EDT 2013

GregM_dxler - Mon Jul 15 10:12:23 EDT 2013

Hi Jenn,

Let's assume that the columns you are looking at are just attributes.

You can find out what attribute this is by the command attrName(col), which will give you a string.  Then you can use that attribute name to set the value.

number(anObject) gives you the object number, not the absolute number (or object identifier).  Is this what you really want?

The second break will break out of for anObject in current Module loop after the first object.  If so, then why even use a loop?

Adding the code doesn't work since I used "o" as the object variable and not "anObject" as you used.

I modified your code to go through the entire module and it will change the text in the 4th column of the object number 1 (providing you have it in edit mode).  Hope this helps you a little.

s = "my test"

Object anObject
Column col
for anObject in current Module do {
    int colCount = 0
    for col in current Module do {
        colCount++
        print "OID=" number(anObject) "  Column=" colCount "\n"
        // Get the object for column 4 of the first row and change that.
        if ( colCount == 4 && number(anObject) == "1" ) {
            string sAttr = attrName(col)
            anObject.sAttr = s
            break
        }
    }
    //break
}
print "done"

Greg

Adding the code doesn't work since I used "o" as the object variable and not "anObject" as you used.

Sorry, I meant I put in the double quotes to cast it.

I used:

attrName(col)

and it works.

Thank you so much, Greg!

Re: Add Text to a Cell
llandale - Tue Jul 16 14:48:43 EDT 2013

"above the one I'm on" stuck out loudly.  Let's not confuse

  • the "current Object", which is the one selected and the "one I'm on"; with
  • the "Object o" handle in a DXL script.

Your variable "o" can point to any object you want (in your case, whatever algorithm you use to find the cell) but that won't change the selected "current Object".

A new object is not being created but I wonder if perhaps a new one is being displayed because you have some filter on.

As for the code; perhaps this works better.  I'm scribbling you will need tor resolve syntax:

  • Module m = current
  • string NameAttr = attrName(column (m, 4))   // get "Column" handle for 4th column, then attrName in that Column
  • if (null NameAttr) then column 4 does not display an attribute.  Maybe Layout or Main.
  • Object o, oFound = false
  • for o in m do
  • {  if (number(o) == "1") then{oFound = o; break}
  • }
  • if (null oFound) then there is no object currently displayed with paragraph "number" of "1"
  • oFound.NameAttr = s

-Louie